package cool.webstudy.admin.controller.dict;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import cool.webstudy.admin.model.dto.dict.data.CreateDictDataDTO;
import cool.webstudy.admin.model.dto.dict.data.PaginationQueryDictDataDTO;
import cool.webstudy.admin.model.dto.dict.data.UpdateDictDataDTO;
import cool.webstudy.admin.model.vo.dict.data.PaginationQueryDictDataVO;
import cool.webstudy.admin.model.vo.dict.data.QueryDictDataByDictTypeListVO;
import cool.webstudy.admin.service.DictDataService;
import cool.webstudy.admin.utils.aspect.request.RequestParameterCheck;
import cool.webstudy.admin.utils.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 作者：陈先生
 * 日期：2024/8/3
 * 描述:
 */
@Tag(name = "字典值管理")
@RestController
@RequestMapping("/dict-data")
@RequestParameterCheck
public class DictDataController {
    @Autowired
    private DictDataService dictDataService;

    @PostMapping("/create")
    @Operation(summary = "创建字典值接口")
    public Result create(@RequestBody CreateDictDataDTO createDictDataDTO){
        dictDataService.createDictData(createDictDataDTO);
        return Result.success();
    }

    @PostMapping("/delete")
    @Operation(summary = "删除字典值")
    public Result delete(@RequestBody(required = true) String unCode){
        dictDataService.deleteDictData(unCode);
        return Result.success();
    }

    @PostMapping("/update")
    @Operation(summary = "更新字典值")
    public Result update(@RequestBody(required = true)UpdateDictDataDTO dto){
        dictDataService.updateDictData(dto);
        return Result.success();
    }

    @GetMapping("/query/by-type")
    @Operation(summary = "根据字典类型查询字典值接口")
    public Result queryDictDataByDictType(@RequestParam(required = true) String type){
        List<QueryDictDataByDictTypeListVO> vo = dictDataService.queryDictDataByDictTypeListVO(type);
        return Result.success(vo);
    }
    @PostMapping("/page-query/list")
    @Operation(summary = "分页获取字典值信息列表接口")
    public Result<Page<PaginationQueryDictDataVO>> paginationQueryDictDataInfoList(@RequestBody PaginationQueryDictDataDTO dto) {
        Page<PaginationQueryDictDataVO> vo = dictDataService.paginationQueryDictDataByDictTypeListVO(dto);
        return Result.success(vo);
    }
}
